package com.max.oracle;

import com.max.fileutils.PropertyUtils;

import java.sql.*;
import java.util.Properties;

public class JdbcOracleApp{

    public static Connection getConnection() throws Exception{
        Properties properties = PropertyUtils.loadProperties("oracle.properties");
        String host = properties.getProperty("oracle.host");
        String port = properties.getProperty("oracle.port");
        String timeout = properties.getProperty("oracle.timeout");
        String sid = properties.getProperty("oracle.sid");
        String service_name = properties.getProperty("oracle.service_name");
        String username = properties.getProperty("oracle.username");
        String password = properties.getProperty("oracle.password");
        String driver = properties.getProperty("oracle.driver");
        String url = "jdbc:oracle:thin:@"+host+":"+port+":"+sid;

        Class.forName("oracle.jdbc.OracleDriver");
        Connection con = DriverManager.getConnection(url, username, password);
        return con;
    }

    public static void main(String[]args) throws Exception {
        // TODO Auto-generated method stub
        Connection con = getConnection();
        String sql="select * from emp";
        PreparedStatement ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while(rs.next())
        {
            for (int i=1;i<7;i++) {
                System.out.print(rs.getNString(i)+"|");
            }
            System.out.println();
        }
    }
}
